import { Form, Modal, InputNumber } from 'antd';
import React from 'react';

const GenerateNetworkParams = props => {
  const { visible, onSuccess, onCancel, callback } = props;

  // States
  const [form] = Form.useForm();

  // Handlers
  const handleSubmit = async () => {
    callback(form.getFieldValue());
    onSuccess();
  };

  const formItemLayout = {
    labelCol: {
      sm: { span: 24 },
      md: { span: 6 },
    },
    wrapperCol: {
      sm: { span: 24 },
      md: { span: 16 },
    },
  };
  // Renders
  return (
    <Modal
      maskClosable={false}
      visible={visible}
      title={'设置网络参数'}
      okText={'提交'}
      cancelText={'取消'}
      onOk={handleSubmit}
      onCancel={onCancel}
    >
      <Form
        form={form}
        name={'post-review'}
        layout={'horizontal'}
        {...formItemLayout}
        hideRequiredMark={true}
      >
        <Form.Item
          name={'networkNum'}
          label={'网络数'}
          rules={[{ required: true, message: '网络数为必填项' }]}
        >
          <InputNumber min={2} defaultValue={6} placeholder={'请输入'} style={{ width: '100%' }} />
        </Form.Item>
        <Form.Item
          name={'nodeNum'}
          label={'顶点数'}
          rules={[{ required: true, message: '顶点数为必填项' }]}
        >
          <InputNumber
            min={10}
            defaultValue={100}
            placeholder={'请输入'}
            style={{ width: '100%' }}
          />
        </Form.Item>
        <Form.Item
          name={'communityNum'}
          label={'集群数'}
          rules={[{ required: true, message: '集群数为必填项' }]}
        >
          <InputNumber min={2} defaultValue={10} placeholder={'请输入'} style={{ width: '100%' }} />
        </Form.Item>
        <Form.Item
          name={'i_p_edgeNum'}
          label={'集群内的正边数'}
          rules={[{ required: true, message: '集群内正边数为必填项' }]}
        >
          <InputNumber
            min={20}
            defaultValue={300}
            placeholder={'请输入'}
            style={{ width: '100%' }}
          />
        </Form.Item>
        <Form.Item
          name={'i_n_degeNum'}
          label={'集群内的负边数'}
          rules={[{ required: true, message: '集群内负边数为必填项' }]}
        >
          <InputNumber min={0} defaultValue={0} placeholder={'请输入'} style={{ width: '100%' }} />
        </Form.Item>
        <Form.Item
          name={'o_p_edgeNum'}
          label={'集群间的正边数'}
          rules={[{ required: true, message: '集群间正边数为必填项' }]}
        >
          <InputNumber min={0} defaultValue={0} placeholder={'请输入'} style={{ width: '100%' }} />
        </Form.Item>
        <Form.Item
          name={'o_n_edgeNum'}
          label={'集群间的负边数'}
          rules={[{ required: true, message: '集群间负边数为必填项' }]}
        >
          <InputNumber min={0} defaultValue={50} placeholder={'请输入'} style={{ width: '100%' }} />
        </Form.Item>
      </Form>
    </Modal>
  );
};

export default GenerateNetworkParams;
